package fhv.at.imageprocessing.editors;

import javax.media.jai.KernelJAI;

public class SobelKernelEditor extends KernelEditor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public SobelKernelEditor() {
		super();
		init();
	}

	private void init() {
		addPreDefinedItem("Sobel - horizontal");
		addPreDefinedItem("Sobel - vertical");
		addPreDefinedItem("Sobel - diagonal 1");
		addPreDefinedItem("Sobel - diagonal 2");
	}

	@Override
	protected void setPreDefinedKernel(String kernelName) {

		if (kernelName.equals("Sobel - horizontal")) {
			setKernelSobelHoricontal();
		} else if (kernelName.equals("Sobel - vertical")) {
			setKernelSobelVertical();
		} else if (kernelName.equals("Sobel - diagonal 1")) {
			setKernelSobelDiagonal1();
		} else if (kernelName.equals("Sobel - diagonal 2")) {
			setKernelSobelDiagonal2();
		} else {
			setKernelDefault();
		}
		pcs.firePropertyChange("", null, null);
	}

	private void setKernelSobelHoricontal() {
		float[] kernelData = { -1.0F, 0.0F, 1.0F, -2.0F, 0.0F, 2.0F, -1.0F,
				0.0F, 1.0F, };
		kernel = new KernelJAI(3, 3, kernelData);
		setValue(kernel);
	}

	private void setKernelSobelVertical() {
		float[] kernelData = { -1.0F, -2.0F, -1.0F, 0.0F, 0.0F, 0.0F, 1.0F,
				2.0F, 1.0F, };
		kernel = new KernelJAI(3, 3, kernelData);
		setValue(kernel);
	}

	private void setKernelSobelDiagonal1() {
		float[] kernelData = { 0.0F, -1.0F, -2.0F, 1.0F, 0.0F, -1.0F, 2.0F,
				1.0F, 0.0F, };
		kernel = new KernelJAI(3, 3, kernelData);
		setValue(kernel);
	}

	private void setKernelSobelDiagonal2() {
		float[] kernelData = { -2.0F, -1.0F, 0.0F, -1.0F, 0.0F, 1.0F, 0.0F,
				1.0F, 2.0F, };
		kernel = new KernelJAI(3, 3, kernelData);
		setValue(kernel);
	}
}
